package com.bjsxt.base.reentrance_shuoGG;

import java.util.concurrent.locks.ReentrantLock;

/*
 * ReentrantLock和synchronized一样都是可重入的
 *
 * 输出结果: 12 12 11 11 13 13
 * */
public class ReentranceSimple implements Runnable {

    ReentrantLock lock = new ReentrantLock();

    public void get() {
        lock.lock();
        System.out.println(Thread.currentThread().getId());
        set();
        lock.unlock();
    }

    public void set() {
        lock.lock();
        System.out.println(Thread.currentThread().getId());
        lock.unlock();
    }

    @Override
    public void run() {
        get();
    }

    public static void main(String[] args) {
        ReentranceSimple ss = new ReentranceSimple();
        new Thread(ss).start();
        new Thread(ss).start();
        new Thread(ss).start();
    }
}
